package com.guaoran.interview.in2018.collection.set;

import java.util.HashSet;
import java.util.Set;

/**
 * @Author gucheng
 * @Description
 *  HashSet 实际上用HashMap进行存储，value值是一个object
 * 2019-03-19 9:36
 */
public class HashSetDemo {
    public static void main(String[] args) {
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < 11; i++) {
            System.out.println(set.add(i));
        }
        //set 如果返回值不是true，说明存在重复值
        System.out.println(set.add(10));

        getStringLength();
    }

    public static void getStringLength() {
        //判断字符串不重复的长度
        String s = "abcabcabc";
        char[] chars = s.toCharArray();
        Set<Character> ch = new HashSet<>();
        for (char c : chars) {
            if (!ch.add(c)) {
                break;
            }
        }
        System.out.println(ch.size());
    }

}